import { valIsNull } from "./utils"

export default {
	token: {
		get() {
			return wx.getStorageSync("IV_token")
		},
		set(token) {
			wx.setStorageSync("IV_token", token)
		},
	},
	//学校是否开启显示联系客服入口
	showContractKefuBtn: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_showContractKefuBtn")) {
				case "true":
					boolean = true
					break
				default:
					boolean = false
					break
			}
			return boolean
		},
		set(showContractKefuBtn) {
			switch (showContractKefuBtn) {
				case false:
					wx.setStorageSync("IV_showContractKefuBtn", "false")
					break
				case true:
					wx.setStorageSync("IV_showContractKefuBtn", "true")
					break
			}
		},
	},
	//学校是否开启新生须知浮窗
	showNewComerNoticeFloat: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_showNewComerNoticeFloat")) {
				case "true":
					boolean = true
					break
				default:
					boolean = false
					break
			}
			return boolean
		},
		set(showNewComerNoticeFloat) {
			switch (showNewComerNoticeFloat) {
				case false:
					wx.setStorageSync("IV_showNewComerNoticeFloat", "false")
					break
				case true:
					wx.setStorageSync("IV_showNewComerNoticeFloat", "true")
					break
			}
		},
	},
	//token过期时间
	tokenExpireAt: {
		set(tokenExpireAt) {
			//date类型的时间进行序列化存储
			wx.setStorageSync("IV_tokenExpireAt", JSON.stringify(tokenExpireAt))
		},
		get() {
			//date类型的时间进行反序列化读取
			if (!valIsNull(wx.getStorageSync("IV_tokenExpireAt"))) {
				return parseInt(wx.getStorageSync("IV_tokenExpireAt"))
			} else {
				return null
			}
		},
	},
	userInfo: {
		get() {
			const jsonString = wx.getStorageSync("IV_userInfo")
			if (jsonString) {
				return JSON.parse(wx.getStorageSync("IV_userInfo"))
			} else {
				return null
			}
		},
		set(userInfo) {
			wx.setStorageSync("IV_userInfo", JSON.stringify(userInfo))
		},
	},
	//是否需要上传位置
	needLocation: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_needLocation")) {
				case "false":
					boolean = false
					break
				default:
					boolean = true
					break
			}
			return boolean
		},
		set(needLocation) {
			switch (needLocation) {
				case false:
					wx.setStorageSync("IV_needLocation", "false")
					break
				case true:
					wx.setStorageSync("IV_needLocation", "true")
					break
			}
		},
	},
	//是否需要手写签名
	needHandleSignature: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_needHandleSignature")) {
				case "false":
					boolean = false
					break
				default:
					boolean = true
					break
			}
			return boolean
		},
		set(needHandleSignature) {
			switch (needHandleSignature) {
				case false:
					wx.setStorageSync("IV_needHandleSignature", "false")
					break
				case true:
					wx.setStorageSync("IV_needHandleSignature", "true")
					break
			}
		},
	},
	//是否需要上传身份证正反面
	needSfzImageUpload: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_needSfzImageUpload")) {
				case "false":
					boolean = false
					break
				default:
					boolean = true
					break
			}
			return boolean
		},
		set(needSfzImageUpload) {
			switch (needSfzImageUpload) {
				case false:
					wx.setStorageSync("IV_needSfzImageUpload", "false")
					break
				case true:
					wx.setStorageSync("IV_needSfzImageUpload", "true")
					break
			}
		},
	},
	//人脸照片是否需要背景模糊
	replaceBg: {
		set(val) {
			switch (val) {
				case false:
					wx.setStorageSync("IV_replaceBg", "false")
					break
				case true:
					wx.setStorageSync("IV_replaceBg", "true")
					break
			}
		},
		get() {
			let boolean
			switch (wx.getStorageSync("IV_replaceBg")) {
				case "false":
					boolean = false
					break
				case "true":
					boolean = true
					break
			}
			return boolean
		},
	},
	//位置信息
	location: {
		get() {
			return wx.getStorageSync("IV_location")
		},
		set(location) {
			wx.setStorageSync("IV_location", location)
		},
	},
	//身份证人像面
	sfz_front: {
		get() {
			return wx.getStorageSync("IV_sfz_front")
		},
		set(val) {
			wx.setStorageSync("IV_sfz_front", val)
		},
	},
	//身份证国徽面
	sfz_back: {
		get() {
			return wx.getStorageSync("IV_sfz_back")
		},
		set(val) {
			wx.setStorageSync("IV_sfz_back", val)
		},
	},
	//人脸照片
	face: {
		get() {
			return wx.getStorageSync("IV_face")
		},
		set(val) {
			wx.setStorageSync("IV_face", val)
		},
	},
	faceImageId: {
		get() {
			return wx.getStorageSync("IV_faceImageId")
		},
		set(val) {
			wx.setStorageSync("IV_faceImageId", val)
		},
	},
	//是否限制核验
	limitState: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_limitState")) {
				case "false":
					boolean = false
					break
				default:
					boolean = true
					break
			}
			return boolean
		},
		set(limitState) {
			switch (limitState) {
				case false:
					wx.setStorageSync("IV_limitState", "false")
					break
				case true:
					wx.setStorageSync("IV_limitState", "true")
					break
			}
		},
	},
	// 是否已经阅读了协议详情
	hasReadAgreementDetail: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_hasReadAgreementDetail")) {
				case "true":
					boolean = true
					break
				default:
					boolean = false
					break
			}
			return boolean
		},
		set(val) {
			switch (val) {
				case false:
					wx.setStorageSync("IV_hasReadAgreementDetail", "false")
					break
				case true:
					wx.setStorageSync("IV_hasReadAgreementDetail", "true")
					break
			}
		},
	},
	// 是否同意协议
	agreement: {
		get() {
			let boolean
			switch (wx.getStorageSync("IV_agreement")) {
				case "true":
					boolean = true
					break
				default:
					boolean = false
					break
			}
			return boolean
		},
		set(val) {
			switch (val) {
				case false:
					wx.setStorageSync("IV_agreement", "false")
					break
				case true:
					wx.setStorageSync("IV_agreement", "true")
					break
			}
		},
	},
	// 是否开启定位限制，对象中的属性包括：centerLatitude 中心点纬度，centerLongitude 中心点经度，distance 限制半径，limit 是否开启定位限制
	locationLimit: {
		set(obj) {
			wx.setStorageSync("IV_locationLimit", JSON.stringify(obj))
		},
		get() {
			return JSON.parse(wx.getStorageSync("IV_locationLimit"))
		},
	},
	//用于在登录页面自动选择学校
	schoolId: {
		set(val) {
			wx.setStorageSync("IV_schoolId", val)
		},
		get() {
			return wx.getStorageSync("IV_schoolId")
		},
	},
	//最大可重试次数
	maxRetryCount: {
		set(val) {
			wx.setStorageSync("IV_maxRetryCount", val)
		},
		get() {
			if (
				wx.getStorageSync("IV_maxRetryCount") !== null &&
				wx.getStorageSync("IV_maxRetryCount") !== undefined &&
				wx.getStorageSync("IV_maxRetryCount") !== ""
			) {
				//转化为数字类型
				return parseInt(wx.getStorageSync("IV_maxRetryCount"))
			} else {
				return null
			}
		},
	},
}
